import java.util.concurrent.TimeUnit;

/**
 * @author wcj
 * @Date 2021/6/8 11:09
 * @Version 1.0
 */
public class Interrupted {

    /**
     * 中断标识位：在发生中断异常和线程终止的时候，中断标识位都会被清除为false
     *
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Thread sleep = new Thread(new SleepRunner(), "SleepRunner");
        sleep.setDaemon(true);
        Thread busy = new Thread(new BusyRunner(), "BusyRunner");
        busy.setDaemon(true);
        sleep.start();
        busy.start();
        TimeUnit.SECONDS.sleep(5);
        sleep.interrupt();
        busy.interrupt();
        System.out.println("Sleep interrupt:" + sleep.isInterrupted());
        System.out.println("Busy interrupt:" + busy.isInterrupted());
        SleepUtils.second(2);
    }

    static class SleepRunner implements Runnable {

        @Override
        public void run() {
            while (true) {
                SleepUtils.second(10);
            }
        }
    }

    static class BusyRunner implements Runnable {

        @Override
        public void run() {
            while (true) {

            }
        }
    }
}
